package com.gp;

import com.gp.exploredao.exploreInformation;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "explored")
public class explored extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String value = request.getParameter("value");
        List<String> exolore = new exploreInformation().getExolore(value);
        StringBuilder result = new StringBuilder();
        result.append("[");
        int i = 0;
        for (String s : exolore) {
            if (i == 0) {
                result.append("{\"value\":\"" + s + "\"}");
            } else {
                result.append(",{\"value\":\"" + s +"\"}");
            }
            i++;
        }
        response.setContentType("text/html;Charset=UTF-8");
        result.append("]");
        System.out.println(result);
        
        response.getWriter().print(result);
    }
}
